/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package callback.serveur;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Hippolyte
 */
public class CallbackServeur {

    public static void main(String[] args) {
        try {
            
            LocateRegistry.createRegistry(1099);

            System.out.println("Mise en place du Security Manager ...");
            if (System.getSecurityManager() == null) {
                System.setSecurityManager(new RMISecurityManager());
            }
            
            CallbackServeurImpl obj = new CallbackServeurImpl();
            String registryURL = "rmi://localhost/callback";
            Naming.rebind(registryURL, obj);
            System.out.println("Le serveur est pret.");
        } catch (MalformedURLException ex) {
            Logger.getLogger(CallbackServeur.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(CallbackServeur.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
//    public static void demarrer(String s, int port) {
    public static CallbackServeurImpl demarrer(int nbDecimal, int nbServeur, int port) {
        
        CallbackServeurImpl obj = null;
        
        try {
            
            LocateRegistry.createRegistry(port);

            System.out.println("Mise en place du Security Manager ...");
            if (System.getSecurityManager() == null) {
                System.setSecurityManager(new RMISecurityManager());
            }
            
            obj = new CallbackServeurImpl(nbDecimal,nbServeur);
            String registryURL = "rmi://localhost/callback";
            Naming.rebind(registryURL, obj);
            System.out.println("Le serveur est pret.");
        } catch (MalformedURLException ex) {
            Logger.getLogger(CallbackServeur.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(CallbackServeur.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return obj;
    }
}
